/*
* @Author: gavin
* @Date:   2017-12-23 15:10:43
* @Last Modified by:   gavin
* @Last Modified time: 2017-12-23 22:51:31
*/
import Koa from "koa";
import path from "path";
import render from "koa-ejs";
import compress from "koa-compress";

import { listen, ssr, api } from "@/web/middleware";
import { useStaticRendering } from "mobx-react";
useStaticRendering(true);
const Dir = global.DIR;

// 创建koa服务器应用
export const app = new Koa();

render(app, {
  root: Dir.dist,
  // layout: '__layout',
  // delimiter:@,
  viewExt: "html",
  cache: false,
  debug: false,
});

app.use(compress());
// 配置及初始化Koa服务器
export const creatServer = () => {
  app.use(api);
  app.use(ssr);
  // app.on('error', (err) => {
  // 	console.error('Server error: \n%s\n%s ', err.stack || '');
  // });

  const server = listen(app);
};

export default { app, creatServer };
